﻿using BaoVeThanhDia.GamePlay.Monsters;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics;


namespace BaoVeThanhDia.GamePlay.Monsters
{
    class MonsterEffect
    {
        private string NameEffect;
        private int ValueEffect;
        private int TimeEffect;
        private Texture2D Image;
        private bool isActive;
        private int countDraw;
        public MonsterEffect(string name, int value, int time)
        {
            NameEffect = name;
            ValueEffect = value;
            TimeEffect = time;
            isActive = true;
            countDraw = 0;
        }
        public void Load(ContentManager content)
        {
            if (NameEffect.Equals("Frozen"))
            {
                Image = content.Load<Texture2D>("images/effect/MapEffect2/Layer-1");
            }
            else if (NameEffect.Equals("Slow"))
            {
                Image = content.Load<Texture2D>("images/effect/effect");
            }
            else if (NameEffect.Equals("Stun"))
            {
                Image = content.Load<Texture2D>("images/effect/stunned");
            }
            else if (NameEffect.Equals("Heal"))
            {
                Image = content.Load<Texture2D>("images/effect/heal");
            }
        }
        public void Draw(SpriteBatch sprite, Vector2 Posi, ContentManager content)
        {
            #region nơi load các ảnh amination của hiệu ứng
            if (NameEffect.Equals("Revival") && countDraw < 55)
            {
                Image = content.Load<Texture2D>("images/effect/Revival/attack1.info.areaWarning_" + (11 + countDraw / 5));
            }
            #endregion
            #region nơi vẽ các hiệu ứng
            if (NameEffect.Equals("Frozen") && TimeEffect > 0)
                if (Image.IsDisposed || Image == null)
                {
                }
                else sprite.Draw(Image, (Posi + new Vector2(10, -64)) * GamePage.Scale + GamePage.Dolech, new Rectangle(0, 0, 64, 70), Color.White * 0.7f, 0, Vector2.Zero, 2 * GamePage.Scale, SpriteEffects.None, 0);
            else if (NameEffect.Equals("Slow") && TimeEffect > 0)
                if (Image.IsDisposed || Image == null)
                {
                }
                else sprite.Draw(Image, Posi * GamePage.Scale + GamePage.Dolech, new Rectangle(390, 0, 80, 60), Color.White, 0, Vector2.Zero, 2 * GamePage.Scale, SpriteEffects.None, 0);
            else if (NameEffect.Equals("Stun") && TimeEffect > 0)
                if (Image.IsDisposed || Image == null)
                {
                }
                else sprite.Draw(Image, (Posi + new Vector2(0, -50)) * GamePage.Scale + GamePage.Dolech, new Rectangle(64 * ((TimeEffect / 5) % 4), 0, 64, 25), Color.White, 0, Vector2.Zero, 2 * GamePage.Scale, SpriteEffects.None, 0);
            else if (NameEffect.Equals("Heal"))
                if (Image.IsDisposed || Image == null)
                {
                }
                else sprite.Draw(Image, (Posi + new Vector2(10, -10)) * GamePage.Scale + GamePage.Dolech, new Rectangle(64 * (countDraw / 5), 0, 64, 57), Color.White, 0, Vector2.Zero, 2 * GamePage.Scale, SpriteEffects.None, 0);
            else if (NameEffect.Equals("Revival"))
            {
                if (Image.IsDisposed || Image == null)
                {
                }
                else sprite.Draw(Image, (Posi + new Vector2(10, -100)) * GamePage.Scale + GamePage.Dolech, new Rectangle(0, 0, 64, 88), Color.White, 0, Vector2.Zero, 2 * GamePage.Scale, SpriteEffects.None, 0);
            }
            #endregion
            #region nơi tính toán thời gian hiện các hiệu ứng
            if (!NameEffect.Equals("Heal") && !NameEffect.Equals("Revival"))
            {
                TimeEffect--;
                if (TimeEffect < 0) isActive = false;
            }
            countDraw++;
            if (countDraw >= 55 && NameEffect.Equals("Revival")) isActive = false;
            if (countDraw >= 30 && NameEffect.Equals("Heal")) countDraw = 0;
            #endregion
        }
        public bool getActive() { return isActive; }
        public string getNameEffect() { return NameEffect; }
        public int getValueEffect() { return ValueEffect; }
        public int getTimeEffect() { return TimeEffect; }
        public Texture2D getImage() { return Image; }
    }
}
